/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------
#include <iterator>
#include "oxide-common/str.hpp"
// ----------------------------------------------------------------------------
#ifndef O2_LEX_CURSOR_INCREMENTER_INC
#define O2_LEX_CURSOR_INCREMENTER_INC
namespace o2 {
namespace lex {
namespace detail {
// ----------------------------------------------------------------------------

template <typename IteratorT>
struct cursor_incrementer
{
	typedef IteratorT iterator_type;
	typedef typename std::iterator_traits<iterator_type>::value_type char_type;
	typedef typename std::char_traits<char_type>::off_type offset_type;
	
	cursor_incrementer(void)
		: offset(0)
		, line(0)
		, column(0)
		{ }
		
	iterator_type& operator() (iterator_type& iter)
	{
		++column;
		++offset;

		// Rather naive handling of Windows newlines ...
		switch (*++iter)
		{
			default:
				break;
			case '\r':
				++iter;
				++offset;
			case '\n':
				++line;
				column = 0;
		}
		return iter;
	}

	offset_type offset;
	offset_type line;
	offset_type column;
};

// ----------------------------------------------------------------------------
} // namespace detail
} // namespace lex
} // namespace o2
#endif // O2_LEX_CURSOR_INCREMENTER_INC
// ----------------------------------------------------------------------------
